<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Object.fromEntries()</title>
</head>
<body>
    <h1>Object.fromEntries()</h1>
    <h2>是Object.entries()的逆操作，用于将键值对数组转为对象</h2>

    <script>
        // 基本用法
        const entries = [
            ['name', '张三'],
            ['age', 18]
        ];
        const obj = Object.fromEntries(entries);
        console.log(obj); // {name: '张三', age: 18}

        // Map转对象
        const map = new Map([
            ['foo', 'bar'],
            ['baz', 42]
        ]);
        const obj2 = Object.fromEntries(map);
        console.log(obj2); // {foo: 'bar', baz: 42}
    </script>
</body>
</html> 